package com.hoyo.config;

import org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.thymeleaf.spring4.SpringTemplateEngine;
import org.thymeleaf.spring4.view.ThymeleafViewResolver;
import org.thymeleaf.templateresolver.ServletContextTemplateResolver;


@Configuration
public class HtmlViewResolver extends ThymeleafAutoConfiguration {
	
	@Bean(name="thymeleafViewResolver")
	public ThymeleafViewResolver  thymeleafViewResolver(){
		ThymeleafViewResolver thymeleafViewResolver = new ThymeleafViewResolver();
		String[] viewNames={"*.html"};
		thymeleafViewResolver.setViewNames(viewNames);
		thymeleafViewResolver.setCharacterEncoding("UTF-8");
		thymeleafViewResolver.setTemplateEngine(templateEngine());
		
		return thymeleafViewResolver;
	}
	
	
	@Bean(name="templateResolver")
	public ServletContextTemplateResolver templateResolver(){
		ServletContextTemplateResolver templateResolver =new ServletContextTemplateResolver();
		templateResolver.setPrefix("/WEB-INF/views/templates/");
		templateResolver.setTemplateMode("LEGACYHTML5");
		return templateResolver;
	}
	
	@Bean(name="templateEngine")
	public SpringTemplateEngine templateEngine(){
		SpringTemplateEngine templateEngine =new SpringTemplateEngine();
		templateEngine.setTemplateResolver(templateResolver());
		return templateEngine;
	}
	
}
